home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Online / cnetdevice / src / card_info.asm next >
Assembly Source File  |  1997-12-21  |  11KB  |  534 lines

  1. ;=============================================================================
  2. ;                             PCMCIA Card Info
  3. ;=============================================================================
  4. ;
  5. ;
  6. ;  History:
  7. ;
  8. ; 30-06-97 - Now releases card if attribute presence test fails.
  9. ;
  10. ; 31-08-97 - Reads config and configmap tuples to get config ID
  11. ;
  12. ; 11-12-97 - More analysis of tuples.
  13. ;
  14.  
  15. VERSION  = 0
  16. REVISION = 2
  17.  
  18.  
  19. ; opt d+
  20.  
  21.  output ram:card_info
  22.  
  23.  include start.i
  24.  include pcmcia.i
  25.  include cnet.i
  26.  
  27.  include printf.i
  28.  
  29. ; LONGWINDED=1  to print more sub-tuple details!
  30.  
  31. atmemsize= 4096
  32. cmemsize = 2048-16-16
  33.  
  34. _main:
  35.  move.l  ourtask(pc),a0
  36.  tst.l   pr_cli(a0)
  37.  bne.s   .cli
  38.  lea     consolename(pc),a0
  39.  move.l  a0,d1
  40.  move.l  #MODE_NEWFILE,d2
  41.  DOS     Open
  42.  move.l  d0,ohandle
  43.  beq     _exit
  44.  bra.s   .start
  45. .cli:
  46.  dos     output
  47.  move.l  d0,ohandle
  48. .start:
  49.  printf  <10,"Getting PCMCIA card info...",10,10>
  50.  
  51.  move.l  4.w,a6
  52.  lea     cardname(pc),a1
  53.  jsr     _LVOOpenResource(a6)         ; open credit card resource
  54.  move.l  d0,cardres
  55.  beq.s   error
  56.  move.l  d0,a6
  57.  lea     card_handle(pc),a1
  58.  lea     cardremoved(pc),a0
  59.  move.l  a0,cah_CardRemoved(a1)
  60.  lea     cardinserted(pc),a0
  61.  move.l  a0,cah_CardInserted(a1)      ; set interrupt vectors
  62.  lea     cardstatus(pc),a0
  63.  move.l  a0,cah_CardStatus(a1)
  64.  lea     ourname(pc),a0
  65.  move.l  a0,ln_name(a1)
  66.  move.b  #20,ln_pri(a1)
  67.  move.b  #CARDF_IFAVAILABLE|CARDF_POSTSTATUS,cah_cardflags(a1)
  68. _start:
  69.  jsr     _LVOOwnCard(a6)              ; own card (sets up interrupt vectors)
  70.  tst.l   d0
  71.  beq.s   owned
  72. error:
  73.  printf  <"Card is not inserted, or is already in use!",10>
  74.  moveq   #-1,d0                       ; error if can't own card
  75.  bra     _done
  76. owned:
  77.  lea     card_handle(pc),a1
  78.  move.l  #CARDF_DISABLE_WP|CARDF_ENABLE_DIGAUDIO,d1
  79.  jsr     _LVOCardMiscControl(a6)      ; enable card I/O functions
  80.  
  81.  lea     $a00000,a0
  82.  cmp.b   #$01,(a0)
  83.  beq.s   .good
  84.  printf  <"Attribute memory not detected!",10,"Re-insert card and try again.",10>
  85.  bra     _releasecard
  86. .good:
  87.  lea     atmem(pc),a1
  88.  move.l  #(atmemsize/2)-1,d0
  89. .getattr
  90.  move.b  (a0)+,(a1)+                  ; get attribute memory
  91.  addq.l  #1,a0                        ; skipping odd bytes
  92.  dbf     d0,.getattr
  93.  
  94.  lea     card_handle(pc),a1
  95.  lea     tuple(pc),a0
  96.  moveq   #CISTPL_INFO_V1,d1
  97.  move.l  #256,d0
  98.  jsr     _LVOCopyTuple(a6)            ; get info tuple
  99.  tst.l   d0
  100.  beq     .getfid
  101. .got_info
  102.  lea     tuple(pc),a0
  103.  moveq   #0,d2
  104.  move.b  1(a0),d2
  105.  subq.w  #1,d2
  106.  bmi     .getfid
  107.  lea     2(a0),a0
  108. .showinfo:
  109.  moveq   #0,d0
  110.  move.b  (a0)+,d0
  111.  cmp.b   #$ff,d0
  112.  beq.s   .endascii
  113.  cmp.b   #' ',d0
  114.  bhs.s   .ascii
  115.  move.b  #'.',d0
  116. .ascii:
  117.  printf  <"%lc">,d0                   ; show information as ascii string
  118.  dbf     d2,.showinfo
  119. .endascii:
  120.  printf  <10,10>
  121. .getfid:
  122.  lea     card_handle(pc),a1
  123.  lea     tuple(pc),a0
  124.  moveq   #CISTPL_FUNC_ID,d1
  125.  move.l  #256,d0
  126.  jsr     _LVOCopyTuple(a6)            ; get Function ID tuple
  127.  tst.l   d0
  128.  beq     .getconfigmap
  129. .got_func_id:
  130.  lea     tuple(pc),a0
  131.  moveq   #0,d0
  132.  move.b  2(a0),d0
  133.  cmp.b   #9,d0
  134.  blo.s   .goodfunc
  135.  printf  <"Card function is unknown",10,10>
  136.  bra.s   .getconfigmap
  137. .goodfunc:
  138.  lsl.w   #2,d0
  139.  lea     functab(pc),a0
  140.  move.l  (a0,d0.w),a0
  141.  printf  <"Appears to be a %s card",10,10>,a0
  142. .getconfigmap:
  143.  lea     card_handle(pc),a1
  144.  lea     tuple(pc),a0
  145.  moveq   #CISTPL_CONF_MAP,d1
  146.  move.l  #256,d0
  147.  jsr     _LVOCopyTuple(a6)            ; get config map tuple
  148.  tst.l   d0
  149.  bne.s   .got_configmap
  150.  printf  <"No Config Map tuple found",10>
  151.  bra     .save
  152. .got_configmap:
  153.  lea     tuple(pc),a0
  154.  move.b  2(a0),d2
  155.  move.b  d2,d0
  156.  and.w   #$03,d0                      ; (number of address bytes)-1
  157.  moveq   #0,d6
  158. .getconfigaddr:
  159.  lsl.l   #8,d6
  160.  move.b  4(a0,d0.w),d6                ; collect config register address
  161.  dbf     d0,.getconfigaddr
  162.  
  163.  lea     card_handle(pc),a1
  164.  lea     tuple(pc),a0
  165.  moveq   #CISTPL_CONFIG,d1
  166.  move.l  #256,d0
  167.  jsr     _LVOCopyTuple(a6)            ; get config tuple
  168.  tst.l   d0
  169.  bne.s   .gotconfig
  170.  printf  <"No Config tuple found",10>
  171.  bra     .save
  172. .gotconfig:
  173.  moveq   #0,d0
  174.  lea     tuple(pc),a0
  175.  move.b  2(a0),d3
  176.  moveq   #0,d7
  177.  move.b  d3,d7
  178.  and.b   #$3f,d7                      ; extract configuration ID value
  179.  move.b  d2,d0
  180.  and.w   #$03,d0                      ; (number of address bytes)-1
  181.  addq.w  #1,d0
  182.  mulu    #8,d0
  183.  
  184.  printf  <"CCR Offset address (%ld bit) = $%06lx, Config ID = $%02lx",10,10>,d0,d6,d7
  185.  
  186.  lea     3(a0),a0
  187.  btst    #7,d3
  188.  beq     .noface
  189.  move.b  (a0)+,d2
  190.  move.b  d2,d0
  191.  and.b   #$0f,d0
  192.  printf  <"Interface Type %ld, uses: ">,d0
  193.  btst    #4,d2
  194.  beq.s   .nobv
  195.  printf  <"BVD ">
  196. .nobv:
  197.  btst    #5,d2
  198.  beq.s   .nowp
  199.  printf  <"WP ">
  200. .nowp:
  201.  btst    #6,d2
  202.  beq.s   .nordy
  203.  printf  <"RDYBSY">
  204. .nordy:
  205.  btst    #7,d2
  206.  beq.s   .nowait
  207.  printf  <"WAIT ">
  208. .nowait:
  209.  printf  <10,10>
  210. .noface:
  211.  IFD     LONGWINDED
  212.  move.b  (a0)+,d2
  213.  move.b  d2,d4
  214.  and.l   #$03,d4
  215.  beq     .nopower
  216.  printf  <"Power sub-tuple(s):",10>
  217. .power:
  218.  bsr     showpower
  219.  subq.b  #1,d4
  220.  bne.s   .power
  221. .nopower:
  222.  btst    #2,d2
  223.  beq     .notime
  224.  printf  <10,"Timing sub-tuple:",10>
  225.  move.b  (a0)+,d1
  226.  move.b  d1,d0
  227.  and.b   #$03,d0
  228.  printf  <" Wait=%ld">,d0
  229.  cmp.b   #3,d0
  230.  beq.s   .noextwait
  231.  move.b  (a0)+,d0
  232.  printf  <" ExtWait=%ld">,d0
  233. .noextwait:
  234.  move.b  d1,d0
  235.  and.b   #$1c,d0
  236.  lsr.b   #2,d0
  237.  printf  <" Ready=%ld">,d0
  238.  cmp.b   #7,d0
  239.  beq.s   .noextready
  240.  move.b  (a0)+,d0
  241.  printf  <" ExtReady=%ld">,d0
  242. .noextready:
  243.  move.b  d1,d0
  244.  and.b   #$e0,d0
  245.  lsr.b   #6,d0
  246.  printf  <" Rsrvd=%ld">,d0
  247.  cmp.b   #7,d0
  248.  beq.s   .noextres
  249.  move.b  (a0)+,d0
  250.  printf  <" ExtRsrvd=%ld">,d0
  251. .noextres:
  252.  printf  <10,10>
  253. .notime:
  254.  btst    #3,d2
  255.  bne     .noio
  256.  printf  <"I/O space sub-tuple:",10>
  257.  move.b  (a0)+,d1
  258.  move.b  d1,d0
  259.  and.b   #$1f,d0
  260.  printf  <" I/O Address lines = $%02lx",10>,d0
  261.  btst    #5,d1
  262.  beq.s   .no8bit
  263.  printf  <" 8bit I/O present",10>
  264. .no8bit:
  265.  btst    #6,d1
  266.  beq.s   .no16bit
  267.  printf  <" 16bit I/O present",10>
  268. .no16bit:
  269.  btst    #7,d1
  270.  beq.s   .norange
  271.  printf  <" I/O has range",10>
  272. .norange:
  273.  movem.l d2-d7,-(sp)
  274.  move.b  (a0)+,d7          ; d7 = count/iosize/blocksize
  275.  move.b  d7,d0
  276.  and.b   #$0f,d0
  277.  printf  <" %ld I/O sub-tuples:",10>
  278.  move.b  d0,d2             ; d2 = number of sub-tuples-1
  279.  move.b  d7,d3
  280.  and.w   #$30,d3
  281.  lsr.b   #4,d3             ; d3 = size of address value
  282.  move.b  d7,d4
  283.  and.w   #$c0,d4
  284.  lsr.b   #6,d4             ; d4 = size of i/o block value
  285. .showio:
  286.  moveq   #0,d0
  287.  move.b  d3,d1
  288. .getaddr
  289.  subq.b  #1,d1
  290.  beq.s   .gotaddr
  291.  lsl.l   #8,d0
  292.  move.b  (a0)+,d0
  293.  bra.s   .getaddr
  294. .gotaddr:
  295.  printf  <" Address = $%08lx, ">,d0
  296.  move.b  d4,d1
  297.  moveq   #0,d0
  298. .getrange:
  299.  subq.b  #1,d1
  300.  beq.s   .gotrange
  301.  lsl.l   #8,d0
  302.  move.b  (a0)+,d0
  303.  bra.s   .getrange
  304. .gotrange:
  305.  printf  <"range = %ld bytes",10>,d0
  306.  dbf     d2,.showio
  307.  movem.l (sp)+,d2-d7
  308. .noio:
  309.  btst    #4,d2
  310.  bne.s   .noirq
  311.  printf  <"IRQ sub-tuple:",10>
  312.  move.b  (a0)+,d1
  313.  btst    #5,d1
  314.  beq.s   .nolev
  315.  printf  <" Level triggered",10>
  316. .nolev:
  317.  btst    #6,d1
  318.  beq.s   .notrig
  319.  printf  <" Pulse triggered",10>
  320. .notrig:
  321.  btst    #4,d1
  322.  beq.s   .nomask
  323.  addq.l  #2,a0        ; skip mask
  324. .nomask:
  325. .noirq:
  326.  move.b  d2,d4
  327.  and.l   #$60,d4
  328.  beq.s   .nomemspace
  329.  lsr.b   #6,d4
  330.  printf  <"%ld memory space sub-tuple(s):",10>,d4
  331. .nomemspace:
  332.  btst    #7,d2
  333.  beq.s   .nomisc
  334.  printf  <"Miscellaneous sub-tuple:",10>
  335. .nomisc:
  336.  
  337.  ENDC   ; LONGWINDED
  338.  
  339.  lea     $a00000,a0                   ; a0 = attribute memory
  340.  and.l   #$0001FFFF,d6
  341.  move.b  d7,(a0,d6.l)                 ; configure IO space
  342.  
  343.  lea     $a00000,a0
  344.  add.l   d6,a0              ; we want to see if ccr value was accepted
  345.  lea     cmem(pc),a1
  346.  move.l  #(cmemsize/2)-1,d0
  347. .getccr
  348.  move.w  (a0)+,(a1)+        ; get card configuration register values
  349.  dbf     d0,.getccr
  350.  
  351. .save:
  352.  printf  <"Getting I/O memory now - remove card if system freezes!",10>
  353.  
  354.  lea     $a20000,a0
  355.  lea     imem,a1
  356.  move.l  #(1024)-1,d0
  357. .getio
  358.  move.b  (a0)+,(a1)+                  ; get I/O
  359.  subq.l  #1,d0
  360.  bpl.s   .getio
  361.  
  362.  printf  <10,"Saving data to %s",10>,#filename
  363.  
  364.  move.l  #filename,d1
  365.  move.l  #MODE_NEWFILE,d2
  366.  dos     open
  367.  move.l  d0,d4
  368.  bmi.s   _releasecard
  369.  lea     atmem(pc),a0
  370.  move.l  a0,d2
  371.  move.l  #(atmemsize/2)+16+cmemsize+16+1024,d3
  372.  move.l  d4,d1
  373.  dos     write
  374.  move.l  d4,d1
  375.  dos     close
  376.  
  377. _releasecard:
  378.  lea     card_handle(pc),a1
  379.  moveq   #CARDF_REMOVEHANDLE,d0
  380.  move.l  cardres(pc),a6
  381.  jsr     _LVOReleaseCard(a6)
  382. _done:
  383.  printf  <10,"card_info done.",10>
  384.  move.l  ourtask(pc),a0
  385.  tst.l   pr_cli(a0)
  386.  bne.s   .nocon
  387.  move.l  ohandle(pc),d1
  388.  beq.s   .nocon
  389.  DOS     Close
  390. .nocon:
  391.  moveq   #0,d0
  392.  rts
  393.  
  394.  
  395. ; show a power sub-tuple
  396.  
  397. showpower:
  398.  move.l  d2,-(sp)
  399.  move.b  (a0)+,d1        ; get block bitmap
  400.  moveq   #7,d2
  401. .block
  402.  lsr.b   #1,d1
  403.  bcc.s   .noblock        ; bit set = power block exists
  404. .byte:
  405.  move.b  (a0)+,d0
  406.  printf  <" $%02lx">,d0  ; show block byte
  407.  btst    #7,d0           ; any more bytes in block ?
  408.  bne.s   .byte
  409. .noblock:
  410.  dbf     d2,.block       ; next block
  411.  printf  <10>
  412.  move.l  (sp)+,d2
  413.  rts
  414.  
  415.  
  416.  
  417. ;============================================================
  418. ;             PCMCIA status change interrupt handler
  419. ;============================================================
  420. ;  input:   d0 = status change(s)
  421. ;           a1 = user defined
  422. ;
  423. ;  output:  d0 must be preserved!
  424. ;
  425. ;
  426. status_int_code:
  427.  rts
  428.  
  429.  
  430. card_inserted_code:
  431.  rts
  432.  
  433. card_removed_code:
  434.  rts
  435.  
  436. ourname:
  437.  dc.b "pcmcia test interrupt",0
  438. cardname:
  439.  dc.b "card.resource",0
  440.  even
  441.  
  442. cardremoved:
  443.  dc.l 0,0
  444.  dc.b 0,0
  445.  dc.l 0
  446.  dc.l 0
  447.  dc.l card_removed_code
  448.  
  449. cardinserted:
  450.  dc.l 0,0
  451.  dc.b 0,0
  452.  dc.l 0
  453.  dc.l 0
  454.  dc.l card_inserted_code
  455.  
  456. cardstatus:
  457.  dc.l 0,0
  458.  dc.b 0,0
  459.  dc.l 0
  460.  dc.l 0                 ; value to be placed in A1 at interrupt time
  461.  dc.l status_int_code
  462.  
  463.  
  464. functab:
  465.  dc.l func0
  466.  dc.l func1
  467.  dc.l func2
  468.  dc.l func3
  469.  dc.l func4
  470.  dc.l func5
  471.  dc.l func6
  472.  dc.l func7
  473.  dc.l func8
  474.  dc.l func9
  475.  
  476. func0:
  477.  dc.b "Multifunction",0
  478. func1:
  479.  dc.b "Memory",0
  480. func2:
  481.  dc.b "Serial",0
  482. func3:
  483.  dc.b "Parallel",0
  484. func4:
  485.  dc.b "Fixed",0
  486. func5:
  487.  dc.b "Video",0
  488. func6:
  489.  dc.b "Network",0
  490. func7:
  491.  dc.b "AIMS",0
  492. func8:
  493.  dc.b "SCSI",0
  494. func9:
  495.  dc.b "Unknown",0
  496.  
  497.  
  498. consolename:
  499.   dc.b  "CON:10/20/600/170/ card_info /WAIT/CLOSE",0
  500.  
  501.  
  502. VersionString:
  503.  dc.b    "$VER: card_info "
  504.  dc.b    (VERSION+"0"),".",(REVISION+"0")," "
  505.  dc.b    __DATE
  506.  dc.b    " by Bruce Abbott",10,0
  507.  even
  508.  
  509. ;--------------------------------------------------------
  510. ;                     Global data
  511. ;--------------------------------------------------------
  512.  
  513. cardres:
  514.   dc.l 0             ; card.resource base
  515.  
  516. tuple:
  517.  ds.b    256+8       ; PCMCIA tuple buffer
  518.  
  519. card_handle:
  520.   ds.b  cah_sizeof   ; handle for our card
  521.  
  522. filename:
  523.   dc.b  "t:card_info.bin",0
  524.   even
  525.  
  526. atmem:
  527.   ds.b  (atmemsize/2)
  528.   dc.b  "===== ccr ======"
  529. cmem:
  530.   ds.b  cmemsize
  531.   dc.b  "===== I/O ======"
  532. imem:
  533.   ds.b  1024
  534.